package org.yenn.pattern.aliyun.structural.filtercriteria.impl;

import org.yenn.pattern.aliyun.structural.filtercriteria.Criteria;
import org.yenn.pattern.aliyun.structural.filtercriteria.Person;

import java.util.List;
/**
 * 步骤 3
 * 创建实现了 Criteria 接口的实体类。
 */
public class AndCriteria implements Criteria {
    private Criteria criteria;
    private Criteria otherCriteria;

    public AndCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> persons) {
        List firstCriteriaPersons = criteria.meetCriteria(persons);
        return otherCriteria.meetCriteria(firstCriteriaPersons);
    }
}
